package com.thales.au.sytst;

import java.io.*;

public class TestBOM {
	/**
     * UTF-8 Byte Order Mark
     */
     public static final int BOM = 65279;

	/*
	 * Make sure 0xFEFF is encoded as this byte sequence: EF BB BF, when UTF-8
	 * is being used, and parsed back into 0xFEFF.
	 */
	public static void main(String[] args) throws Exception {

		/*
		 * Write
		 */
		FileOutputStream fos = new FileOutputStream("bom.txt");
		OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF8");
		osw.write(0xFEFF);
		osw.close();

		/*
		 * Parse
		 */
		FileInputStream fis = new FileInputStream("bom.txt");
		InputStreamReader isr = new InputStreamReader(fis, "UTF8");
		char bomChar = (char) isr.read();
		System.out.println("Parsed: "
				+ Integer.toHexString(bomChar).toUpperCase());
		if (bomChar != 0xFEFF) {
			throw new Exception("Invalid BOM: "
					+ Integer.toHexString(bomChar).toUpperCase());
		}
		isr.close();

	}

}